<?php
session_start();
$currPage = "manage";
include("inc_header.php"); ?>

	<div id="content">
		<h2><a href="#">Account Info</a></h2>
		<div class="clearfix">
			<form name="usrInfoForm" method="post" action="checkUsrInfo.php">

				<?php
				$usrName = $_SESSION['username'];
				echo '<h3>' . $usrName . '</h3>';
				?>
				
				<table>
					<tr>
						<td>Old Password:</td>
						<td><input type="password" value="" name="oldPword" id="oldPword" size="16" maxlength="15" /> (required)</td>
					</tr><tr>
						<td>New Passowrd:</td>
						<td><input type="password" value="" name="newPword" id="newPword" size="16" maxlength="15" /></td>
					</tr>
					
				<?php
				$host="mysql-user.cse.msu.edu"; // Host name
				$username="hewittry"; // Mysql username
				$password="A39777266"; // Mysql password
				$db_name="hewittry"; // Database name


				$usrName = $_SESSION['username'];
				$usrType = $_SESSION['usertype'];

				// Connect to server and select databse.
				mysql_connect("$host", "$username", "$password")or die("cannot connect");
				mysql_select_db("$db_name")or die("cannot select DB");

				
				$sqlNonAdmin="SELECT * FROM NonAdmins WHERE AllUsers_LogonID='$usrName'";
				$nonAdminResult=mysql_query($sqlNonAdmin);
				$nonAdminRow = mysql_fetch_row($nonAdminResult);

				$email = $nonAdminRow[1];
				$telephone = $nonAdminRow[2];
				$city = $nonAdminRow[3];
				$state = $nonAdminRow[4];

				echo '<tr><td>Email:</td>
				<td><input type="text" value="' . $email . '" name="newEmail" id="newEmail" size="40"  maxlength="30"/></td>
				</tr>';

				echo '<tr><td>Telephone:</td>
				<td><input type="text" value="' . $telephone . '" name="newTelephone" id="newTelephone" size="40"  maxlength="15"/></td>
				</tr>';

				echo '<tr><td>City:</td>
				<td><input type="text" value="' . $city . '" name="newCity" id="newCity" size="40" maxlength="40" /></td>
				</tr>';

				echo '<tr><td>State:</td>
				<td><input type="text" value="' . $state . '" name="newState" id="newState" size="3"  maxlength="2"/></td>
				</tr>';					

				//if(isset($dealerRow[0])) //Dealer
				if($usrType == "RegUser")		//Reg User
				{

					$sqlRegUsr="SELECT * FROM RegisteredUser WHERE NonAdmins_AllUsers_LogonID='$usrName'";
					$regUsrResult=mysql_query($sqlRegUsr);
					$regUsrRow = mysql_fetch_row($regUsrResult);
					$name = $regUsrRow[1];

					echo '<tr><td>Name:</td>
						<td><input type="text" value="' . $name . '" name="newName" id="newName" size="40"  maxlength="40"/></td>
						</tr>';
				}
				else if($usrType == "Dealer")
				{

					$sqlDealer="SELECT * FROM Dealer WHERE NonAdmins_AllUsers_LogonID='$usrName'";
					$dealerResult=mysql_query($sqlDealer);

					while ($dealerRow = mysql_fetch_assoc($dealerResult))
					{						
						$coName = $dealerRow["CompanyName"];
						$streetNum = $dealerRow["StreetNo"];
						$streetName = $dealerRow["StreetName"];
						$zipcode = $dealerRow["Zipcode"];
						$url = $dealerRow["URL"];
						$desc = $dealerRow["description"];

						echo '<tr><td colspan="2"><strong><br />Dealer Information<br /><br /></strong></td></tr>';
						
						echo '<tr><td>Company Name:</td>
							<td><input type="text" value="' . $coName . '" name="newCoName" id="newCoName" size="40" maxlength="30"/></td>
							</tr>';
			
						echo '<tr><td>Street Number:</td>
							<td><input type="text" value="' . $streetNum . '" name="newStreetNum" id="newStreetNum" size="12" maxlength="11"/></td>
							</tr>';

						echo '<tr><td>Street Name:</td>
							<td><input type="text" value="' . $streetName . '" name="newStreetName" id="newStreetName" size="40" maxlength="30"/></td>
							</tr>';
							
						echo '<tr><td>Zipcode:</td>
							<td><input type="text" value="' . $zipcode . '" name="newZipcode" id="newZipcode" size="12" maxlength="5"/></td>
							</tr>';

						echo '<tr><td>URL:</td>
							<td><input type="text" value="' . $url . '" name="newURL" id="newURL" size="40" maxlength="40"/></td>
							</tr>';
							
						echo '<tr><td style="vertical-align: top;">Description:</td>
							<td><textarea name="description" id="description" style="width: 300px; height: 100px;">' . $desc . '</textarea></td>
							</tr>';
							
						break;
					}
				}

				?>
				
				<tr><td>&nbsp;</td>
				<td><input type="submit" value="Update" name="submit" id="submit" /></td>
				</tr>
				</table>
				
			</form>
		</div>

	</div>

<?php include("inc_footer.php"); ?>
